package mlz.d_bstcp;

import mlz.d_tcp3.ServerReaderThread;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static void main(String[] args) throws IOException {

        System.out.println("----服务器启动成功----");

        ServerSocket serverSocket = new ServerSocket(8080);

        //等待客户端连接
        Socket socket = serverSocket.accept();

        System.out.println("有客户端上线了~~" + socket.getRemoteSocketAddress());

        //启动客户端对应的socket
        new ServerReaderThread(socket).start();

        //使用线程池做优化 ->
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                5,
                10,
                8,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(8),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());


    }
}








